package com.xhwl.centiotdata.handler.pedestrian;

import com.xhwl.centiotdata.pojo.dto.pedestrian.PedestrianIntegrationConfigDTO;
import com.xhwl.centiotdata.service.cent.IAuthAccountCentService;
import com.xhwl.common.dto.auth.PedestrianAuthDTO;
import com.xhwl.common.dto.cent.device.DeviceDTO;
import com.xhwl.common.dto.cent.pedes.OpenDoorRecordDTO;
import com.xhwl.common.enums.pedestrian.DoorActionEnum;
import com.xhwl.common.pojo.ResultJson;
import com.xhwl.common.pojo.cent.auth.TransitionCardInfo;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Author： lianghz
 * @Description：
 * @Date 2021/09/06/ 11:22
 */
public abstract class PedestrianIntegrationHandler implements InitializingBean {

    public void pullRecord(PedestrianIntegrationConfigDTO pedestrianIntegrationConfigDTO, Integer intervalDays, Date date) {
        throw new UnsupportedOperationException();
    }
    public void pullFaceRecord(PedestrianIntegrationConfigDTO pedestrianIntegrationConfigDTO, Integer intervalDays, Date date) {
        throw new UnsupportedOperationException();
    }

    public void syncThirdAuthorizedDoorInfo(PedestrianAuthDTO pedestrianAuthDTO, PedestrianIntegrationConfigDTO configDTO) {
        throw new UnsupportedOperationException();
    }

    public ResultJson openDoor(PedestrianIntegrationConfigDTO pedestrianIntegrationConfigDTO, DeviceDTO deviceDTO, DoorActionEnum doorAction) {
        throw new UnsupportedOperationException();
    }

    public ResultJson createAuth(PedestrianIntegrationConfigDTO configDTO, PedestrianAuthDTO pedestrianAuthDTO) {
        throw new UnsupportedOperationException();
    }

    public ResultJson updateAuth(PedestrianIntegrationConfigDTO configDTO, PedestrianAuthDTO pedestrianAuthDTO) {
        throw new UnsupportedOperationException();
    }

    public ResultJson deleteAuth(PedestrianIntegrationConfigDTO configDTO, PedestrianAuthDTO pedestrianAuthDTO) {
        throw new UnsupportedOperationException();
    }

    public void pullClockRecord(PedestrianIntegrationConfigDTO configDTO, Integer offSet, Integer limit) {
        throw new UnsupportedOperationException();
    }

    public void pushRecord(Object data, Integer projectId) {
        throw new UnsupportedOperationException();
    }

    public void pullVisits(PedestrianIntegrationConfigDTO configDTO, Date date) {
        throw new UnsupportedOperationException();
    }

    public void pullRecordStatistics(PedestrianIntegrationConfigDTO pedestrianIntegrationConfigDTO, Integer intervalDays) {
        throw new UnsupportedOperationException();
    }

    public ResultJson addUser(PedestrianIntegrationConfigDTO configDTO, PedestrianAuthDTO pedestrianAuthDTO) {
        throw new UnsupportedOperationException();
    }
    public ResultJson deleteUser(PedestrianIntegrationConfigDTO configDTO, PedestrianAuthDTO pedestrianAuthDTO) {
        throw new UnsupportedOperationException();
    }
    public ResultJson  updateUser(PedestrianIntegrationConfigDTO configDTO, PedestrianAuthDTO pedestrianAuthDTO) {
        throw new UnsupportedOperationException();
    }

    public ResultJson getInsideQrCode( PedestrianIntegrationConfigDTO configDTO,  OpenDoorRecordDTO openDoorRecordDTO){
        throw new UnsupportedOperationException();
    }

    public static void onSavingAuthCards(IAuthAccountCentService service, PedestrianIntegrationConfigDTO configDTO, PedestrianAuthDTO pedestrianAuthDTO) {
        //云屏需要保存转换后的卡号
        List<String> sourceCardNumbers = pedestrianAuthDTO.getSourceCardNumberList();
        if (!CollectionUtils.isEmpty(sourceCardNumbers)) {
            List<String> transitionCardNumbers = new ArrayList<>();
            if(CollectionUtils.isEmpty(pedestrianAuthDTO.getCardNumberList())){
                transitionCardNumbers.add(pedestrianAuthDTO.getCardNumber());
            }else{
                transitionCardNumbers.addAll(pedestrianAuthDTO.getCardNumberList());
            }
            List<TransitionCardInfo> cardInfos = new ArrayList<>();
            for (int i = 0; i < transitionCardNumbers.size(); i++) {
                TransitionCardInfo transitionCard = new TransitionCardInfo();
                transitionCard.setProjectId(pedestrianAuthDTO.getProjectId());
                transitionCard.setTransitionCardNumber(transitionCardNumbers.get(i));
                transitionCard.setSourceCardNumber(sourceCardNumbers.get(i));
                transitionCard.setProductId(configDTO.getProductId());
                transitionCard.setProjectId(pedestrianAuthDTO.getProjectId());
                transitionCard.setCreateAt(new Date());
                cardInfos.add(transitionCard);
            }
            if (!CollectionUtils.isEmpty(cardInfos)) {
                service.saveTransitionCards(cardInfos);
            }
        }
    }
    // 拉取数字哨兵的查验数据
    public void pullCheckData(PedestrianIntegrationConfigDTO configDTO) throws Exception {
        throw new UnsupportedOperationException();
    }
    // 拉取数字哨兵的访客数据
    public void pullVisitorData(Integer intervalDays, PedestrianIntegrationConfigDTO configDTO) throws Exception {
        throw new UnsupportedOperationException();
    }
    /**
     * 修复某一天的数据
     *
     * @param pedestrianIntegrationConfigDTO
     * @param date                           yyyy-MM-dd
     * @return errorMsg null代表成功
     */
    public String repairRecord(PedestrianIntegrationConfigDTO pedestrianIntegrationConfigDTO, String date) {
        throw new UnsupportedOperationException();
    }
}
